package com.ruoyi.creditlife.service.impl;

import com.ruoyi.creditlife.domain.BookInfo;
import com.ruoyi.creditlife.mapper.BookInfoMapper;
import com.ruoyi.creditlife.service.IBookInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 图书信息
Service业务层处理
 * 
 * @author ddd
 * @date 2025-07-10
 */
@Service
public class BookInfoServiceImpl implements IBookInfoService 
{
    @Autowired
    private BookInfoMapper bookInfoMapper;

    /**
     * 查询图书信息

     * 
     * @param bookId 图书信息
主键
     * @return 图书信息

     */
    @Override
    public BookInfo selectBookInfoByBookId(Long bookId)
    {
        return bookInfoMapper.selectBookInfoByBookId(bookId);
    }

    /**
     * 查询图书信息
列表
     * 
     * @param bookInfo 图书信息

     * @return 图书信息

     */
    @Override
    public List<BookInfo> selectBookInfoList(BookInfo bookInfo)
    {
        return bookInfoMapper.selectBookInfoList(bookInfo);
    }

    /**
     * 新增图书信息

     * 
     * @param bookInfo 图书信息

     * @return 结果
     */
    @Override
    public int insertBookInfo(BookInfo bookInfo)
    {
        return bookInfoMapper.insertBookInfo(bookInfo);
    }

    /**
     * 修改图书信息

     * 
     * @param bookInfo 图书信息

     * @return 结果
     */
    @Override
    public int updateBookInfo(BookInfo bookInfo)
    {
        return bookInfoMapper.updateBookInfo(bookInfo);
    }

    /**
     * 批量删除图书信息

     * 
     * @param bookIds 需要删除的图书信息
主键
     * @return 结果
     */
    @Override
    public int deleteBookInfoByBookIds(Long[] bookIds)
    {
        return bookInfoMapper.deleteBookInfoByBookIds(bookIds);
    }

    /**
     * 删除图书信息
信息
     * 
     * @param bookId 图书信息
主键
     * @return 结果
     */
    @Override
    public int deleteBookInfoByBookId(Long bookId)
    {
        return bookInfoMapper.deleteBookInfoByBookId(bookId);
    }
    public boolean updateBookNum(Long bookId) {
        BookInfo bookInfo = bookInfoMapper.selectBookInfoByBookId(bookId);
        Long booknum = bookInfo.getBookNum();
        if(booknum>0){
            return bookInfoMapper.updateBookNum(bookId);
        }
        else {
            return false;
        }
    }

    @Override
    public List<BookInfo> BookInfoList() {
        return bookInfoMapper.BookInfoList();
    }
}
